//
//  NSString+CLY.m
//  Xingbei
//
//  Created by SRH on 15/10/26.
//  Copyright © 2015年 reformer. All rights reserved.
//

#import "NSString+CLY.h"
#import <CommonCrypto/CommonDigest.h>

@implementation NSString (CLY)

- (CGFloat)cly_stringHeightWithFont:(UIFont *)font width:(CGFloat)width{
    return [self boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size.height;
}

- (CGSize)cly_stringSizeWithFont:(UIFont *)font{
    return [self sizeWithAttributes:@{NSFontAttributeName:font}];
}

- (NSString *)cly_MD5String{
    const char *cstr = [self UTF8String];
    unsigned char result[16];
    CC_MD5(cstr, (CC_LONG)strlen(cstr), result);
    return [NSString stringWithFormat:
            @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
            result[0], result[1], result[2], result[3],
            result[4], result[5], result[6], result[7],
            result[8], result[9], result[10], result[11],
            result[12], result[13], result[14], result[15]
            ];
}
- (CGSize)sizeWithFont:(UIFont *)font maxW:(CGFloat)maxW
{
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = font;
    CGSize maxSize = CGSizeMake(maxW, MAXFLOAT);
    return [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}

- (float) heightForString:(NSString *)value andWidth:(float)width{
    //获取当前文本的属性
    NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:value];
    NSRange range = NSMakeRange(0, attrStr.length);
    // 获取该段attributedString的属性字典
    NSDictionary *dic = [attrStr attributesAtIndex:0 effectiveRange:&range];
    // 计算文本的大小
    CGSize sizeToFit = [value boundingRectWithSize:CGSizeMake(width - 16.0, MAXFLOAT) // 用于计算文本绘制时占据的矩形块
                                           options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading // 文本绘制时的附加选项
                                        attributes:dic        // 文字的属性
                                           context:nil].size; // context上下文。包括一些信息，例如如何调整字间距以及缩放。该对象包含的信息将用于文本绘制。该参数可为nil
    return sizeToFit.height + 16.0;
}

- (CGSize)sizeWithFont:(UIFont *)font
{
    return [self sizeWithFont:font maxW:MAXFLOAT];
}

//写PList
+ (BOOL)writePlistWithFileName:(NSString *)fileName inDocument:(NSString *)direct withData:(id)data{
    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    // get documents path
    NSString *documentsPath = [paths objectAtIndex:0];
    // get the path to our Data/plist file
    if (direct.length >0) {
        NSFileManager *fileManager = [NSFileManager defaultManager];
        documentsPath = [documentsPath stringByAppendingPathComponent:direct];
        [fileManager createDirectoryAtPath:documentsPath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    
    NSString *plistPath = [documentsPath stringByAppendingPathComponent:fileName];
    
    DLog(@"writeplistPath=%@",plistPath);
    NSString *error = nil;
    // create NSData from dictionary
    NSError *errorkk = nil;
    
    NSData *plistData = [NSPropertyListSerialization dataWithPropertyList:data format:NSPropertyListXMLFormat_v1_0
                                                                  options:0 error:&errorkk];

    // Use dataWithPropertyList:format:options:error: instead
    
    // check is plistData exists
    if(plistData)
    {
        // write plistData to our Data.plist file
        BOOL dbool = [data writeToFile:plistPath atomically:YES];
        if (!dbool) {
            DLog(@"witeFile Failure");
        }
        return dbool;
    }
    else
    {
        DLog(@"Error in saveData: %@", error);
        return NO;
    }
    
}

//读PList
+ (id)readPListWithFileName:(NSString *)fileName
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    // get documents path
    NSString *documentsPath = [paths objectAtIndex:0];
    // get the path to our Data/plist file
    NSString *plistPath = [documentsPath stringByAppendingPathComponent:fileName];
    DLog(@"plistPath = %@",plistPath);
    // check to see if Data.plist exists in documents
    
    if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath])
    {
        return nil;
        /*
         // if not in documents, get property list from main bundle
         NSArray *array = [fileName componentsSeparatedByString:@"."];
         plistPath = [[NSBundle mainBundle] pathForResource:[array objectAtIndex:0] ofType:[array objectAtIndex:1]];
         */
    }
    
    // read property list into memory as an NSData object
    NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
    NSString *errorDesc = nil;
    NSPropertyListFormat format;
    
    id __strong temp = [NSPropertyListSerialization propertyListWithData:plistXML options:NSPropertyListMutableContainersAndLeaves format:&format error:&errorDesc];

    if (!temp)
    {
        //            DLog(@"Error reading plist: %@, format: %u", errorDesc, format);
    }
    return temp;
}



/*手机号码验证 MODIFIED BY HELENSONG*/
-(BOOL) isValidateMobile
{
    //手机号以13， 15，18开头，八个 \d 数字字符
    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    //    DLog(@"phoneTest is %@",phoneTest);
    return [phoneTest evaluateWithObject:self];
}


/**
 * 获取当前时间
 *
 *  @return 时间
 */
+(NSString *)getNowTime{
    NSDate *  senddate=[NSDate date];
    
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    
    [dateformatter setDateFormat:@"YYYY-MM-dd kk:mm:ss"];
    
    NSString *  locationString=[dateformatter stringFromDate:senddate];
    return locationString;
}

+(NSString *)getNowTimeMinus{
    NSDate *  senddate=[NSDate date];
    
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    
    [dateformatter setDateFormat:@"mm:ss"];
    
    NSString *  locationString=[dateformatter stringFromDate:senddate];
    return locationString;
}



+(NSString *)getNowTimeexactMinutes{
    NSDate *  senddate=[NSDate date];
    
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    
    [dateformatter setDateFormat:@"MM-dd kk:mm"];
    
    NSString *  locationString=[dateformatter stringFromDate:senddate];
    return locationString;
}


+(NSString *)getNowTimeexactDay{
    NSDate *  senddate=[NSDate date];
    
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    
    [dateformatter setDateFormat:@"YYYY-MM-dd"];
    
    NSString *  locationString=[dateformatter stringFromDate:senddate];
    return locationString;
}


+(NSString*)readUsrPhoneID
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *token = [defaults objectForKey:UserPhoneID];
    return token;
}

+(BOOL)validateCarNo:(NSString* )carNo
{
    NSString *carRegex = @"^[\u4e00-\u9fa5]{1}[A-H_J-N_P-Z]{1}[A-H_J-N_P-Z_0-9]{5}$";
    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];
    NSLog(@"carTest is %@",carTest);
    return [carTest evaluateWithObject:carNo];
}


+(NSString *)readnickName{
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString *tt = [accountDefaults objectForKey:@"nickName"];
    return tt;
}

+(void)savenickName:(NSString *)nickName{
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    [accountDefaults setValue:nickName forKey:@"nickName"];
    [accountDefaults synchronize];
}


+(void)saveUserId:(NSString *)userId{
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    [accountDefaults setValue:userId forKey:@"memberId"];
    [accountDefaults synchronize];
}

+(NSString*)readUserId{
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    return [accountDefaults objectForKey:@"memberId"];
}


+(void)saveLocoalCity:(NSString *)city{
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    [accountDefaults setValue:city forKey:@"locoalCity"];
    [accountDefaults synchronize];
}

+(NSString*)readLocoalCity{
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    return [accountDefaults objectForKey:@"locoalCity"];
}



+(NSString *)readPhone{
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString *tt = [accountDefaults objectForKey:@"phone"];
    return tt;
}

+(void)removeInfo{
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    [accountDefaults removeObjectForKey:@"phone"];
    [accountDefaults removeObjectForKey:@"userId"];
    [accountDefaults synchronize];

}

+(void)savePhoneNumber:(NSString*)number{
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    [accountDefaults setValue:number forKey:@"phone"];
    [accountDefaults synchronize];
}


-(BOOL)telephoneisValidateMobile
{
    //手机号以13， 15，18开头，八个 \d 数字字符
    //[1][358]\\d{9}
    //^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8]))//d{8}$
    NSString *phoneRegex = @"^\\d{11}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    //    DLog(@"phoneTest is %@",phoneTest);
    return [phoneTest evaluateWithObject:self];
}


- (BOOL)validateIdentityCard
{
//    BOOL flag;
//    if (self.length <= 0) {
//        flag = NO;
//        return flag;
//    }
    NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";
    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
    return [identityCardPredicate evaluateWithObject:self];
}


+(void)saveRegister:(NSInteger)number;
{
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    [accountDefaults setInteger:number forKey:@"register"];
    [accountDefaults synchronize];
}


+(NSInteger)readRegisetrStatus{
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSInteger reg = [[accountDefaults objectForKey:@"register"] integerValue];
    return reg;
}

+(BOOL) isBlankString:(NSString *)string {
    if (string == nil || string == NULL) {
        return YES;
    }
    if ([string isKindOfClass:[NSNull class]]) {
        return YES;
    }
    return NO;
}




+(NSString *)readMacAdress{
    return [CLYUserDefaults objectForKey:@"macAddress"];
}

+(void)saveManufacturer:(NSString *)name{
    [CLYUserDefaults setValue:name forKey:@"FIRM_NAME"];
    [CLYUserDefaults synchronize];
}


+(NSString *)readManufacturerName{
    return [CLYUserDefaults objectForKey:@"FIRM_NAME"];
}


+(NSString *)createDylogoImage{
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    NSString *filename=[path stringByAppendingPathComponent:@"dylogoImage.plist"];   //获取路径
    return filename;
}


+(NSString *)createPlistAddress:(NSString *)adressName{
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    NSString *lastName = [adressName stringByAppendingString:@".plist"];
    NSString *filename=[path stringByAppendingPathComponent:lastName];   //获取路径
    return filename;
}

+(NSString *)createImagePath{
    //获取Documents文件夹目录
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentPath = [path objectAtIndex:0];
    //指定新建文件夹路径
    NSString *imageDocPath = [documentPath stringByAppendingPathComponent:@"ImageFile"];
    //创建ImageFile文件夹
    [[NSFileManager defaultManager] createDirectoryAtPath:imageDocPath withIntermediateDirectories:YES attributes:nil error:nil];
    //保存图片的路径
     return [imageDocPath stringByAppendingPathComponent:@"image1.png"];
}


//mac地址的处理
+ (NSString *)loadBackDealWith:(NSString *)preStr{
    NSString *totalStr = [[NSString alloc]init];
    preStr = preStr.uppercaseString;
    for (int i=0; i<preStr.length; i=i+2) {
        NSString *tempSt = [preStr substringWithRange:NSMakeRange(i, 2)];
        NSString *middle = [tempSt stringByAppendingString:@":"];
        totalStr = [totalStr stringByAppendingString:middle];
    };
    return [totalStr substringToIndex:totalStr.length-1];
}


+ (NSString*)loadImageUrl{
    //获取Documents文件夹目录
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentPath = [path objectAtIndex:0];
    //指定新建文件夹路径
    NSString *imageDocPath = [documentPath stringByAppendingPathComponent:@"ImageFile"];
    //创建ImageFile文件夹
    [[NSFileManager defaultManager] createDirectoryAtPath:imageDocPath withIntermediateDirectories:YES attributes:nil error:nil];
    //保存图片的路径
    return  [imageDocPath stringByAppendingPathComponent:@"image1.png"];
}


- (BOOL)pwdIsValidate{
    //6-20位数字和字母组成
    NSString *regex = @"^[0-9A-Za-z]{6,20}$";
    NSPredicate *   pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    if ([pred evaluateWithObject:self]) {
        return YES ;
    }else
        return NO;
}

+(void)removeUserId{
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    [accountDefaults removeObjectForKey:@"memberId"];
    [accountDefaults synchronize];
}



+ (void)saveMessageValue:(NSString *)value Key:(NSString *)key{
    NSUserDefaults *defaults = CLYUserDefaults;
    [defaults setValue:value forKey:key];
    [defaults synchronize];
}

+ (void)deleUserPhoneAndPassWord{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults removeObjectForKey:@"userPhoneNumber"];
    [defaults removeObjectForKey:@"userLoginPassWord"];
    [defaults synchronize];
}



+ (BOOL)isEmpty:(NSString *)aStr
{
    //    if(aStr == nil|| aStr == NULL) {
    //        return YES;
    //    }
    if (aStr == nil || [aStr isEqual:[NSNull null]] || aStr.length == 0 || [aStr isEqualToString:@""]) {
        return YES;
    }
    
    NSString *theStr = [self removeEndSpaceFrom:aStr];
    if (theStr.length == 0 || [theStr isEqualToString:@""]) {
        return YES;
    }
    
    NSString *subStr = [self removeLineFeedFrom:aStr];
    if (subStr.length == 0 || [subStr isEqualToString:@""]) {
        return YES;
    }
    return NO;
}


+(NSString *)removeLineFeedFrom:(NSString *)headerData{
    headerData = [headerData stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];  //去除掉首尾的空白字符和换行字符
    headerData = [headerData stringByReplacingOccurrencesOfString:@"\r" withString:@""];
    headerData = [headerData stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    return headerData;
}



+(NSString *)removeEndSpaceFrom:(NSString *)strtoremove{
    NSUInteger location = 0;
    unichar charBuffer[[strtoremove length]];
    [strtoremove getCharacters:charBuffer];
    NSInteger i = 0;
    for ( i = [strtoremove length]; i >0; i--){
        if (![[NSCharacterSet whitespaceCharacterSet] characterIsMember:charBuffer[i - 1]]){
            break;
        }
    }
    return  [strtoremove substringWithRange:NSMakeRange(location, i  - location)];
}



//手机号码
+ (NSString *)loadUserLoginPhone{
    return [CLYUserDefaults objectForKey:@"userPhoneNumber"];
}

//密码
+ (NSString *)loadUserLoginPassWord{
    return [CLYUserDefaults objectForKey:@"userLoginPassWord"];
}

+ (NSMutableAttributedString *)dealWithSt:(NSString *)name1  Name2:(NSString *)name2 {
    NSMutableAttributedString *textAttribute = [[NSMutableAttributedString alloc] init];
    UIColor *kkColor;
    if ([name1 isEqualToString:@"未知"]) {
        kkColor =  RGBACOLOR(17, 206, 109);
    }else{
        if ([name1 floatValue]>10) {
            kkColor =  RGBACOLOR(17, 206, 109);
        }else if ([name1 floatValue]>5){
            kkColor = UIColorFromRGB(0xff6600);
        }else{
            kkColor = [UIColor redColor];
        }
    }
    
    NSAttributedString *doctorName = [[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",name1] attributes:@{NSForegroundColorAttributeName:kkColor,NSFontAttributeName:[UIFont systemFontOfSize:19]}];
    
    [textAttribute appendAttributedString:doctorName];
    
    NSAttributedString *lastName = [[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",name2] attributes:@{NSForegroundColorAttributeName:kkColor,NSFontAttributeName:[UIFont systemFontOfSize:15]}];
    
    [textAttribute appendAttributedString:lastName];
    
    
    return textAttribute;
}


/**
 *  获取未来某个日期是星期几
 *  注意：featureDate 传递过来的格式 必须 和 formatter.dateFormat 一致，否则endDate可能为nil
 *
 */
+ (NSString *)featureWeekdayWithDate:(NSString *)featureDate{
    // 创建 格式 对象
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    // 设置 日期 格式 可以根据自己的需求 随时调整， 否则计算的结果可能为 nil
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    // 将字符串日期 转换为 NSDate 类型
    NSDate *endDate = [formatter dateFromString:featureDate];
    // 判断当前日期 和 未来某个时刻日期 相差的天数
    long days = [NSString daysFromDate:[NSDate date] toDate:endDate];
    // 将总天数 换算为 以 周 计算（假如 相差10天，其实就是等于 相差 1周零3天，只需要取3天，更加方便计算）
    long day = days >= 7 ? days % 7 : days;
    long week = [NSString getNowWeekday] + day;
    switch (week) {
        case 1:
            return @"周日";
            break;
        case 2:
            return @"周一";
            break;
        case 3:
            return @"周二";
            break;
        case 4:
            return @"周三";
            break;
        case 5:
            return @"周四";
            break;
        case 6:
            return @"周五";
            break;
        case 7:
            return @"周六";
            break;
            
        default:
            break;
    }
    
    
    return nil;
}

/**
 *  计算2个日期相差天数
 *  startDate   起始日期
 *  endDate     截至日期
 */
+(NSInteger)daysFromDate:(NSDate *)startDate toDate:(NSDate *)endDate {
    NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
    // 话说在真机上需要设置区域，才能正确获取本地日期，天朝代码:zh_CN
    dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    //得到相差秒数
    NSTimeInterval time = [endDate timeIntervalSinceDate:startDate];
    int days = ((int)time)/(3600*24);
    int hours = ((int)time)%(3600*24)/3600;
    int minute = ((int)time)%(3600*24)/3600/60;
    //days <= 0 && hours <= 0&&minute<= 0
    if (days <= 0 && hours <= 0&&minute<= 0) {
        NSLog(@"0天0小时0分钟");
        return 0;
    }
    else {
        NSLog(@"%@",[[NSString alloc] initWithFormat:@"%i天%i小时%i分钟",days,hours,minute]);
        // 之所以要 + 1，是因为 此处的days 计算的结果 不包含当天 和 最后一天\
        （如星期一 和 星期四，计算机 算的结果就是2天（星期二和星期三），日常算，星期一——星期四相差3天，所以需要+1）\
        对于时分 没有进行计算 可以忽略不计
        return days + 1;
    }
}

// 获取当前是星期几
+ (NSInteger)getNowWeekday {
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |
    NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    NSDate *now = [NSDate date];
    // 话说在真机上需要设置区域，才能正确获取本地日期，天朝代码:zh_CN
    calendar.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    comps = [calendar components:unitFlags fromDate:now];
    return [comps weekday];
}

+ (NSInteger) calcDaysFromBegin:(NSDate *)beginDate end:(NSDate *)endDate
{
    //创建日期格式化对象
    NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    
    //取两个日期对象的时间间隔：
    //这里的NSTimeInterval 并不是对象，是基本型，其实是double类型，是由c定义的:typedef double NSTimeInterval;
    NSTimeInterval time=[endDate timeIntervalSinceDate:beginDate];
    
    int days=((int)time)/(3600*24);
    //int hours=((int)time)%(3600*24)/3600;
    //NSString *dateContent=[[NSString alloc] initWithFormat:@"%i天%i小时",days,hours];
    return days;
}

-(NSString *)dealWithResultCode

{
    int a =[self intValue];
    switch (a) {
            
        case 9000:
            
            return @"订单支付成功";
            
            break;
            
        case 8000:
            
            return @"正在处理中";
            
            break;
            
        case 4000:
            
            return @"订单支付失败";
            
            break;
            
        case 6001:
            
            return @"用户中途取消";
            
            break;
            
        case 6002:
            
            return @"网络连接出错";
            
            break;
            
        default:
            
            break;
            
    }
    
    return @"错误不能识别";
}


+ (NSData *)convertHexStrToData:(NSString *)str {
    if (!str || [str length] == 0) {
        return nil;
    }
    
    NSMutableData *hexData = [[NSMutableData alloc] initWithCapacity:8];
    NSRange range;
    if ([str length] % 2 == 0) {
        range = NSMakeRange(0, 2);
    } else {
        range = NSMakeRange(0, 1);
    }
    for (NSInteger i = range.location; i < [str length]; i += 2) {
        unsigned int anInt;
        NSString *hexCharStr = [str substringWithRange:range];
        NSScanner *scanner = [[NSScanner alloc] initWithString:hexCharStr];
        
        [scanner scanHexInt:&anInt];
        NSData *entity = [[NSData alloc] initWithBytes:&anInt length:1];
        [hexData appendData:entity];
        
        range.location += range.length;
        range.length = 2;
    }
    
    return hexData;
}

+ (NSString *)loadEncryptingStr:(Byte[])testByte{
    Byte byte1 =testByte[0] + 0x65;
    Byte byte2 =testByte[1] ^ 0x1a;
    Byte byte3 =testByte[2] ^ 0x44;
    Byte byte4 =testByte[3] + 0xb8;
    Byte byte5 = 0xec ^ 0x9d ^byte1 ^byte2 ^byte3 ^byte4;
    NSString *totalStr = [[NSString alloc] initWithFormat:@"c30e07ec9d%x%x%x%x%x",byte1,byte2,byte3,byte4,byte5];
    return totalStr;
}



@end
